<!doctype html>
<html>
<head>
    <title>{$backend_name}-{$code_name}</title>
    <meta name="description" content="">
    {include file="public/head"}
</head>
<body>
<!--header-->
{include file="public/header"}
<div class="tpl-page-container tpl-page-header-fixed">
    <!--menu-->
    {include file="public/menu"}
    <!--html body-->
    <div class="tpl-content-wrapper">
        <!--nav-->
        <div class="tpl-content-page-title">
            {$code_name}
        </div>
        <ol class="am-breadcrumb">
            <li><a href="{:url('index/index')}" class="am-icon-home">首页</a></li>
            <li><a href="{:url('active/index')}">活动</a></li>
            <li class="am-active">{$code_name}</li>
        </ol>
        <!--content-->
        <div class="tpl-portlet-components">
            <div class="portlet-title">
                <div class="caption font-green bold">
                    <span class="am-icon-code"></span> {$code_name}列表
                </div>
                <!--<div class="tpl-portlet-input tpl-fz-ml">
                    <div class="portlet-input input-small input-inline">
                        <div class="input-icon right">
                            <i class="am-icon-search"></i>
                            <input type="text" class="form-control form-control-solid" placeholder="搜索..."></div>
                    </div>
                </div>-->
            </div>
            <div class="tpl-block">
                <div class="am-g">
                    <div class="am-u-sm-12 am-u-md-12">
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <div style="float: left;">
                                    按投票人:
                                    <select name="search_type" class="span1">
                                        <option value="nickname">昵称</option>
                                        <option value="user_id" {eq name="$search_type" value="user_id"}selected{/eq}>id</option>
                                        <option value="from_ip" {eq name="$search_type" value="from_ip"}selected{/eq}>ip</option>
                                    </select>
                                    <input type="text" name="keywords" value="{$keywords}" style="border:1px solid rgb(169, 169, 169);"/>
                                </div>
                                <div style="float: left;margin-left: 10px;">
                                    <a href="{:url($code.'/index',['active_id'=>$active_id])}" class="am-btn am-btn-default am-btn-primary search_btn">搜索</a>
                                    {if condition="$keywords"}
                                    <a href="{:url($code.'/all_change',['active_id'=>$active_id])}" class="am-btn am-btn-default am-btn-success all-change"
                                       data-status="0" data-text="设为无效">设为无效</a>
                                    <a href="{:url($code.'/all_change',['active_id'=>$active_id])}" class="am-btn am-btn-default am-btn-danger all-change"
                                       data-status="1" data-text="设为有效">设为有效</a>
                                    {/if}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="am-g" style="margin-top:20px;">
                    <div class="am-u-sm-12">
                        <form class="am-form">
                            <table class="am-table am-table-striped am-table-hover table-main">
                                <thead>
                                <tr>
                                    <!--<th class="table-check"><input type="checkbox" class="tpl-table-fz-check"></th>-->
                                    <th>#</th>
                                    <th>投票人id</th>
                                    <th>投票人昵称</th>
                                    
                                    <th>手机</th>
                                    <th>归属地</th>
                                    <th>手机型号</th>
                                    <th>来源ip</th>
                                    <!-- <th>来源设备</th> -->
                                    <th>投票时间</th>
                                    <th>是否有效</th>
                                </tr>
                                </thead>
                                <tbody>
                                {foreach $list as $vo}
                                <tr>
                                    <!--<td><input type="checkbox"></td>-->
                                    <td>{$vo.id}</td>
                                    <td>{$vo.user_id}</td>
                                    <td>
                                        {$vo.nickname?:'(未获得)'}
                                        {switch name="$vo.from_pass_way"}
                                        {case value="wx"}<span class="am-badge am-badge-success am-radius">{$pass_way[$vo.from_pass_way]}</span>{/case}
                                        {case value="yqsbz"}
                                        {if condition='$vo.site'}
                                        <span class="am-badge am-badge-warning  am-radius">{$sites[$vo.site]}</span>
                                        {else/}
                                        <span class="am-badge am-badge-warning  am-radius">{$pass_way[$vo.from_pass_way]}</span>
                                        {/if}
                                        {/case}
                                        {default/}<span class="am-badge am-radius">未知</span>
                                        {/switch}
                                    </td>

                                    <td>{$vo.phone}</td>
                                    <td>{$vo.phone_area}</td>
                                    <td>{$vo.phone_model}</td>
                                    <td>{$vo.from_ip}</td>
                                    <!-- <td>{$vo.from_device?:'(未获得)'}</td> -->
                                    <td>{$vo.create_time|date='Y-m-d H:i:s',###}</td>
                                    
                                    <td>
                                        {if condition="$vo.status"}
                                        <a href="{:url('change_status')}" class="am-btn am-btn-default am-btn-xs am-btn-success change-btn" data-id="{$vo.id}" data-status="0"
                                           data-text="设为无效">设为无效</a>
                                        {else/}
                                        <a href="{:url('change_status')}" class="am-btn am-btn-default am-btn-xs am-btn-danger change-btn"  data-id="{$vo.id}" data-status="1"
                                           data-text="设为有效">设为有效</a>
                                        {/if}
                                    </td>
                                </tr>
                                {/foreach}
                                </tbody>
                            </table>
                            <div class="am-cf">
                                <div class="am-fr">
                                    {$page}
                                </div>
                            </div>
                            <hr>

                        </form>
                    </div>
                </div>
            </div>
            <div class="tpl-alert"></div>
        </div>
    </div>
</div>
<!--js-->
{include file="public/js"}
<script type="text/javascript">
    $('.am-icon-search').click(function(){
        var keywords = $('input[name=keywords]').val();
        window.location.href = '{:url($code."/index",["active_id"=>$active_id])}?keywords='+keywords;
    });

    $('.change-btn').click(function(){
        var _this = $(this);
        var url = _this.attr('href');
        var text = _this.attr('data-text');
        var id = _this.attr('data-id');
        var status = _this.attr('data-status');
        if(confirm('确定要'+text+'么？')){
            $.post(url,{id:id,status:status},function(data){
                alert(data.message);
                if(data.code == 0){
                    if(data.message == '已设为有效'){
                        _this.attr('data-status',0);
                        _this.attr('data-text','设为无效');
                        _this.text('设为无效');
                        _this.removeClass('am-btn-danger').addClass('am-btn-success');
                    }else{
                        _this.attr('data-status',1);
                        _this.attr('data-text','设为有效');
                        _this.text('设为有效');
                        _this.removeClass('am-btn-success').addClass('am-btn-danger');
                    }
                }
            },'json')
        }
        return false;
    });

    {if condition="$keywords"}
    $('.all-change').click(function(){
        var name = [];
        name['nickname']='昵称';
        name['user_id']='ID';
        name['from_ip']='来源ip';
        var _this = $(this);
        var url = _this.attr('href');
        var text = _this.attr('data-text');
        var participant_id = '{$participant_id}';
        var status = _this.attr('data-status');
        if(confirm('由于需要批量操作\n\n请确定要将条件为:\n\n投票人'+name['{$search_type}']+'等于 : {$keywords} 的所有记录\n\n'+text+'么？')){
            $.post(url,{participant_id:participant_id,status:status,'search_type':'{$search_type}','keywords':'{$keywords}'},function(data){
                alert(data.message);
                if(data.code == 0){
                    timed();
                }
            },'json')
        }
        return false;
    });
    {/if}

    function timed()
    {
        var t=setTimeout("location.reload();",1000);
    }

</script>
</body>
</html>